<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
	

	<title>广州电视台G4摇大奖</title>
	<link rel="stylesheet" href="{$_C.hy_path}css/car/main.css">
	<style>

@keyframes shakeScale {
  from {
    transform: scale3d(1, 1, 1);
    -webkit-transform: scale3d(1, 1, 1);
  }
  50% {
    transform: scale3d(1.5, 1.5, 1.5);
    -webkit-transform: scale3d(1.5, 1.5, 1.5);
  }
  to {
    transform: scale3d(1, 1, 1);
    -webkit-transform: scale3d(1, 1, 1);
  }
}
@-webkit-keyframes shakeScale {
  from {
    transform: scale3d(1, 1, 1);
    -webkit-transform: scale3d(1, 1, 1);
  }
  50% {
    transform: scale3d(1.5, 1.5, 1.5);
    -webkit-transform: scale3d(1.5, 1.5, 1.5);
  }
  to {
    transform: scale3d(1, 1, 1);
    -webkit-transform: scale3d(1, 1, 1);
  }
}
.shakeScale {
  animation: shakeScale 2s ease infinite;
  -webkit-animation: shakeScale 2s ease infinite;
}

	</style>
	
</head>
<body onload="init()">
<!-- 
<script type="text/javascript" src="http://zb.weixin.qq.com/nearbycgi/addcontact/BeaconAddContactJsBridge.js">
</script>
  
<script type="text/javascript">
	
	
	 BeaconAddContactJsBridge.ready(function(){
		//判断是否关注
		
		BeaconAddContactJsBridge.invoke('checkAddContactStatus',{} ,function(apiResult){
			
			if(apiResult.err_code == 0){
				var status = apiResult.data;
				if(status == 1){
					
				}else{
					
					//跳转到关注页
				  BeaconAddContactJsBridge.invoke('jumpAddContact');
				}
			}else{
				alert(apiResult.err_msg)
			}
		});
 	}); 
</script> -->
 
	<div class="wrapper cj-wrapper">
		<img src="{$_C.hy_path}images/car/cj-yaobg.png" alt="">
		<div class="yao page-moveScale" id="yao">
			<img src="{$_C.hy_path}images/car/yao.png" alt="">
		</div>
		<div class="gift hide" id="gift" onclick="jump_card()">
			<p>恭喜！恭喜！<a href="javascript:void()" class="shakeScale">点击领取</a></p>
			<p class="gift-info">G4送您<span class="gift-name" id="prize_name"></span>一份</p>
		</div>
	</div>
	<audio loop style="display:none" id="musicBox" src="{$_C.hy_path}images/car/5018.mp3">  
    </audio> 
	 <script src="{$_C.hy_path}/js/zepto.min.js"></script>
	   
	{include file="../Common/g4-share-fensi.html"}
	
<script>
		   
		   
		 
	
		var prize_user_id = "0";
		var is_shake = 0;
		var SHAKE_THRESHOLD = 1500;  
		var last_update = 0;  
		var x = y = z = last_x = last_y = last_z = 0;  
		//音效
		var myaudio = document.getElementById('musicBox');
		
		//跳转领取卡券
		function jump_card()
	    {
	    	window.location.href="index.php?g=mobile&m=car&a=card&id="+prize_user_id+"&ticket={$ticket}";
	    }
	    
		
		//获取是否中奖
	    function ajax_prize()
		  {
			
			  var url = "index.php?g=mobile&m=car&a=ajaxPrize";
				
			  
			  
				$.post(url,"",function(data){
					 
					//alert(data.error);
			         if(data.error==1){
			        	 prize_user_id = data.data.user_id;
			        	/*  alert(prize_user_id); */
			        	/*  $("#money").html(data.data.money+'元'); */
			        	 $("#prize_name").html(data.data.prize_name);
			         }else{
			        	 prize_user_id = 0;
			        	 $("#gift").html('<p>'+data.content+'</p>');
			         }
					 
			           
			           
			       
			            	document.getElementById('yao').className='yao move'; 
			            setTimeout(function(){
			            	
			            	
				          
				            
					            document.getElementById('gift').className='gift moveFromBottom'; 
			            	
				            
			            }, 1500);
			            
					 
				},"json");
	  	  
	    	
		  }
	    
	    
		function init() {  
		    
		    if (window.DeviceMotionEvent) {  
		        window.addEventListener('devicemotion', deviceMotionHandler, false);  
		       
		    } else {  
		        alert('not support mobile event');  
		    }  
		}  
		function deviceMotionHandler(eventData) {  
		    var acceleration = eventData.accelerationIncludingGravity;  
		    var curTime = new Date().getTime();  
		    if ((curTime - last_update) > 100) {  
		        var diffTime = curTime - last_update;  
		        last_update = curTime;  
		        x = acceleration.x;  
		        y = acceleration.y;  
		        z = acceleration.z;  
		        var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;  

		        if (speed > SHAKE_THRESHOLD ) { 
		        	
		        	if(is_shake==0)
		        	{
		        		
				        	 ajax_prize();
				        	 is_shake =1;
				        	        
		        	}
		        	
		        	 myaudio.play();
			         setTimeout("myaudio.pause()",1200);   
		            
		        }else {
		            
		             //document.getElementById('yao_bg').className='yao_bg'
		        }
		        last_x = x;  
		        last_y = y;  
		        last_z = z;  
		    }  
		};
	</script>   
</body>
</html>